package com.forum.mapper;

import com.forum.annotation.AutoFill;
import com.forum.dto.FeedbackPageQueryDTO;
import com.forum.entity.Feedback;
import com.forum.enumeration.OperationType;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface FeedbackMapper {
    @AutoFill(value = OperationType.INSERT)
    @Insert("insert into feedback(user_id,contact_info,feedback_type,content,status,create_time,update_time,ip_address) " +
            "values" +
            "(#{userId},#{contactInfo},#{feedbackType},#{content},#{status},#{createTime},#{updateTime},#{ipAddress})")
    void save(Feedback feedback);

    Page<Feedback> queryList(FeedbackPageQueryDTO feedbackPageQueryDTO);

    @AutoFill(value = OperationType.UPDATE)

    void reply(Feedback feedback);

    @Select("select count(*) from feedback where status=#{feedbackStatus}")
    Integer statistics(String feedbackStatus);

    @Update("update feedback set status=#{status} where id=#{id}")
    void updateStatus(Feedback feedback);
}
